package svc

import (
	"go-weixin/app/diary/api/internal/config"
	"go-weixin/app/diary/rpc/diaryclient"
	"go-weixin/app/usercenter/rpc/userrpcclient"
	"go-weixin/common/apiserver"
	"go-weixin/common/rpcserver"

	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config   config.Config
	DiaryRpc diaryclient.Diary
	UserRpc  userrpcclient.UserCenter
	ApiMDLE  *apiserver.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	rpcMDLE := rpcserver.NewMiddleware()
	userRpc := userrpcclient.NewUserRpcClient(zrpc.MustNewClient(c.UserRpc, zrpc.WithUnaryClientInterceptor(rpcMDLE.ClientRpcMiddleware)))
	return &ServiceContext{
		Config:   c,
		UserRpc:  userRpc,
		ApiMDLE:  apiserver.NewApiMiddleware(userRpc),
		DiaryRpc: diaryclient.NewDiary(zrpc.MustNewClient(c.DiaryRpcConf, zrpc.WithUnaryClientInterceptor(rpcMDLE.ClientRpcMiddleware))),
	}
}
